//
//  PxWidgetCreater.m
//  badboysIOS
//
//  Created by chuantou on 15/12/30.
//  Copyright © 2015年 chuantou. All rights reserved.
//
#import "PxWidgetCreater.h"

@implementation PxWidgetCreater

+ (UIButton*)customerButton
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = [UIColor clearColor];
    
    return btn;
}

+ (PxTextField *)getTextField:(NSString *) palcehoder
{
    PxTextField *textfield3 = [PxTextField new];
    textfield3.indent = 15;
    textfield3.backgroundColor = [UIColor whiteColor];
    textfield3.textColor = [UIColor blackColor];
    textfield3.clearButtonMode = UITextFieldViewModeWhileEditing;
    textfield3.attributedPlaceholder = [[NSAttributedString alloc] initWithString:palcehoder
                                                                       attributes:@{
                                                                                    NSForegroundColorAttributeName: [UIColor colorWithHTMLStr:@"c6c6c6"],
                                                                                    NSFontAttributeName : [UIFont systemFontOfSize:15]
                                                                                    }
                                        ];
    return textfield3;
}

+ (LLYTTextField *)getTextField:(NSString *) title andValue:(NSString *) value
{
    LLYTTextField *field = [[LLYTTextField alloc] initWithFrame:CGRectMake(0, 0, 320, 45)];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, field.height)];
    label.font = [UIFont systemFontOfSize:15];
    label.textColor = [UIColor colorWithHTMLStr:@"444444"];
    label.text = title;
    [label sizeToFit];
    
    field.enabled = NO;
    field.leftView = label;
    field.textColor = [UIColor colorWithHTMLStr:@"484848"];
    field.font = [UIFont systemFontOfSize:12];
    field.textAlignment = NSTextAlignmentRight;
    
    field.text = value;
    
    return field;
}


+(LLYTTextField *)getTextField:(NSString *) title andPlacehoder:(NSString *) palcehoder
{
    LLYTTextField *field = [[LLYTTextField alloc] initWithFrame:CGRectMake(15, 0, 320, 44.5)];
    field.clearButtonMode = UITextFieldViewModeWhileEditing;
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 70, 44.5)];
    label.font = [UIFont systemFontOfSize:14];
    label.textColor = [UIColor colorWithHTMLStr:@"484848"];
    label.text = title;
    
    field.leftView = label;
    field.textColor = [UIColor colorWithHTMLStr:@"333333"];
    field.textAlignment = NSTextAlignmentRight;
    
    field.attributedPlaceholder = [[NSAttributedString alloc] initWithString:palcehoder
                                                                  attributes:@{
                                                                               NSForegroundColorAttributeName: [UIColor colorWithHTMLStr:@"999999"],
                                                                               NSFontAttributeName : [UIFont systemFontOfSize:15]
                                                                               }
                                   ];
    
    
    return field;
}

+(UIView *)getViewWithData:(NSDictionary *)dic andFrame:(CGRect)frame andTarget:(id) target
{
    CGFloat width = CGRectGetWidth(frame);
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 169)];
    bgView.backgroundColor = [UIColor colorWithHTMLStr:@"eeeeee"];
    NSString *imageName = @"Images/th-yellow";
    if ([dic[@"type"] isEqualToString:@"2"])
        imageName = @"Images/th-blue";
    UIImageView *thImg = [UIImageView imageViewWithName:imageName];
    [bgView addSubview:thImg];
    
    UILabel *headerName = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, width, 34)];
    headerName.font = [UIFont systemFontOfSize:12];
    headerName.textColor = [UIColor colorWithHTMLStr:@"444444"];
    headerName.text = dic[@"header"];
    headerName.textAlignment = NSTextAlignmentLeft;
    [bgView addSubview:headerName];
    
    UIView *bodyView = [self getBodyViewWithData:dic andFrame:frame andTarget:target];
    bodyView.top = headerName.bottom;
    [bgView addSubview:bodyView];
    
    return bgView;
}

+(UIView *)getBodyViewWithData:(NSDictionary *)dic andFrame:(CGRect)frame andTarget:(id) target
{
    CGFloat width = CGRectGetWidth(frame);
    
    UIView *bodyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 135)];
    bodyView.backgroundColor = [UIColor whiteColor];
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 1)];
    lineView.backgroundColor = [UIColor colorWithHTMLStr:@"cccccc"];
    [bodyView addSubview:lineView];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 100, 45)];
    label.textAlignment = NSTextAlignmentCenter;
    label.text = @"地址";
    label.font = [UIFont systemFontOfSize:15];
    label.textColor = [UIColor colorWithHTMLStr:@"444444"];
    [label sizeToFit];
    label.top = (45 - label.height)/2;
    [bodyView addSubview:label];
    
    UILabel *rightLabel = [[UILabel alloc] initWithFrame:CGRectMake(label.right + 10, 0, 100, 45)];
    rightLabel.textColor = [UIColor colorWithHTMLStr:@"484848"];
    rightLabel.font = [UIFont systemFontOfSize:12];
    rightLabel.width = width - 30 - label.width;
    rightLabel.text = dic[@"address"];
    rightLabel.numberOfLines = 2;
    [bodyView addSubview:rightLabel];
    
//    LLYTTextField *field1 = [PxWidgetCreater getTextField:@"地址" andValue:dic[@"address"]];
//    field1.left = 15;
//    field1.width = width - 30;
//    [bodyView addSubview:field1];
    
    UIView *lineView2 = [PxGlobal duplicate:lineView];
    lineView2.left = 15;
    lineView2.top = rightLabel.bottom - 1;
    [bodyView addSubview:lineView2];
    
    LLYTTextField *field2 = [PxWidgetCreater getTextField:@"姓名" andValue:dic[@"name"]];
    field2.left = 15;
    field2.width = width - 30;
    field2.top = rightLabel.bottom;
    [bodyView addSubview:field2];
    
    UIView *lineView3 = [PxGlobal duplicate:lineView];
    lineView3.left = 15;
    lineView3.top = field2.bottom - 1;
    [bodyView addSubview:lineView3];
    
    UIImageView *imageView = [UIImageView imageViewWithName:@"Images/phone"];
    imageView.tag = [dic[@"phone"] integerValue];
    imageView.userInteractionEnabled = YES;
    imageView.contentMode = UIViewContentModeCenter;
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:target action:@selector(gotoTel:)];
    [imageView addGestureRecognizer:tapGesture];
    
    [bodyView addSubview:imageView];
    
    LLYTTextField *field3 = [PxWidgetCreater getTextField:@"电话" andValue:dic[@"phone"]];
    field3.left = 15;
    field3.width = width - 30 - imageView.width - 10;
    field3.top = field2.bottom;
    field3.textColor = [UIColor colorWithHTMLStr:@"2f86e9"];
    [bodyView addSubview:field3];
    
    imageView.left = field3.right + 10;
    imageView.top = field3.top;
    imageView.height = field3.height;
    
    UIView *lineView4 = [PxGlobal duplicate:lineView];
    lineView4.top = field3.bottom - 1;
    [bodyView addSubview:lineView4];
    
    return bodyView;
}

+(UILabel *)getUILabelView:(NSString *) value andTarget:(id) target
{
    UIFont *font = [UIFont systemFontOfSize:12];
    CGSize size = [value sizeWithFont:font maxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 27)];
    label.width = size.width + 10;
    label.textAlignment = NSTextAlignmentCenter;
    label.font = font;
    label.textColor = [UIColor colorWithHTMLStr:@"666666"];
    label.text = value;
    label.backgroundColor = [UIColor whiteColor];
    label.userInteractionEnabled = YES;
    
    label.layer.borderColor = [UIColor colorWithHTMLStr:@"cccccc"].CGColor;
    label.layer.borderWidth = 1;
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:target action:@selector(gotoQuery:)];
    [label addGestureRecognizer:tapGesture];
    
    return label;
}

+(UIView *)getStatusNotifyView:(int) status
{
    NSString *text = @"待通知";
    UIColor *color = [UIColor colorWithHTMLStr:@"e78404"];
    NSString *imgName = [NSString stringWithFormat:@"Images/state-%i", status];
    switch (status) {
        case 1:
            text = @"待通知";
            color = [UIColor colorWithHTMLStr:@"e78404"];
//            imgName = [NSString stringWithFormat:@"Images/state-%i", status];
            break;
        case 2:
            text = @"待派送";
            color = [UIColor colorWithHTMLStr:@"ed3d2f"];
//            imgName = [NSString stringWithFormat:@"Images/state-%i", status];
            break;
        case 3:
            text = @"已派送";
            color = [UIColor colorWithHTMLStr:@"2dc04c"];
//            imgName = [NSString stringWithFormat:@"Images/state-%i", status];
            break;
            
        default:
            break;
    }
    UIView * retView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
    label.text = text;
    label.textColor = color;
    label.font = [UIFont systemFontOfSize:15];
    [label sizeToFit];
    [retView addSubview:label];
    
    CGFloat height = label.height;
    
    UIImageView *imgView = [UIImageView imageViewWithName:imgName];
    imgView.left = label.right + 8;
    imgView.height = height;
    imgView.contentMode = UIViewContentModeCenter;
    [retView addSubview:imgView];
    
    return retView;
}

@end